package com.example.demo.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author vaintale
 * @date 2025/6/26
 */
public class RunPythonFACETS {
    public static void main(String[] args) {
        // 这里替换为你的实际文件路径
        String pythonExe =  "/home/vaintale/miniconda3/envs/DGM/bin/python3"; // 如果你的环境用 python3，改成 "python3"

        String scriptPath = "/home/vaintale/projecs/java-code/demo/src/main/resources/scripts/facets.py";


        String networkPath = "/home/vaintale/projecs/java-code/demo/src/main/resources/data/graph/graph.gml";
        String flowPath = "/home/vaintale/projecs/java-code/demo/src/main/resources/data/graph/graph_Flow.csv";
        String targetPath = "/home/vaintale/projecs/java-code/demo/src/main/resources/data/graph/graph_{}.csv";
        String attackTargetPath = "/home/vaintale/projecs/java-code/demo/src/main/resources/data/graph/{}.csv";
// 这里替换为你的实际文件路径
//String pythonExe =  "D:\\home\\pythonEnv\\myenv\\Scripts\\python.exe"; // 如果你的环境用 python3，改成 "python3"
//
//    String scriptPath = "F:\\Code\\demo\\src\\main\\resources\\scripts\\facets.py";
//
//
//    String networkPath = "F:\\Code\\demo\\src\\main\\resources\\data\\graph\\graph.gml";
//    String flowPath = "F:\\Code\\demo\\src\\main\\resources\\data\\graph\\graph_Flow.csv";
//    String targetPath = "F:\\Code\\demo\\src\\main\\resources\\data\\graph\\graph_{}.csv";
//    String attackTargetPath = "F:\\Code\\demo\\\\src\\main\\resources\\data\\graph\\{}.csv";
        try {
            ProcessBuilder pb = new ProcessBuilder(
                    pythonExe, scriptPath, networkPath, flowPath, targetPath, attackTargetPath,"DRL"
            );
            pb.redirectErrorStream(true);
            Process process = pb.start();

            // 读取输出
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }

            int exitCode = process.waitFor();
            System.out.println("Python脚本执行完毕，退出码：" + exitCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
